const Ws = require('ws');

const server = new Ws.Server({port: 8000})

server.on('open', handleOpen)
server.on('close', handleClose)
server.on('error', handleError)
server.on('connection', handleConnection)

function handleOpen() {
    console.log('handleOpen')
}

function handleClose() {
    console.log('handleClose')
}

function handleError() {
    console.log('handleError')
}

function handleConnection(ws) {
    console.log('handleConnection')
    ws.on('message', handleMessage)
}

function handleMessage(msg,isBinary) {
    server.clients.forEach((c) => {
        c.send(msg,{ binary: isBinary })
    })
}

